package main

import (
	"fmt"
)

type treeNode struct {
	value int
	name string
	left,right *treeNode
}

// nil指针也可以调用方法
func (node *treeNode) setValue (value int)  {
	if node == nil {
		return
	}
	node.value = value
}

func (node treeNode) print ()  {
	fmt.Printf("value is %d ,name is %s",node.value,node.name)
}

//工厂函数返回局部变量的地址
func createNode(value int) *treeNode  {
	return &treeNode{
		value:value,
		name:"hah",
	}
}

func main() {
	var root treeNode
	root = treeNode{value:3,name:"go"}
	root.left = &treeNode{}
	root.right = &treeNode{5,"sdf",nil,nil}
	//不论结构还是地址 都用.来访问成员
	root.right.left = new(treeNode)
	root.left.right = createNode(2)

	root.setValue(9)
	root.print()
	fmt.Println()
	root.left.right.print()

}
